package com.honey.mybatis.generator.page;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.ClassDecoration;
import com.honey.compilation.java.Decoration;
import com.honey.compilation.java.EnumField;
import com.honey.compilation.java.Field;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.JavaVisibility;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.MethodDecoration;
import com.honey.compilation.java.Parameter;
import com.honey.core.compiler.CompilationException;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractClass;

public class DirEnum extends AbstractClass{

	private static final  FullyQualifiedJavaType DIR = new FullyQualifiedJavaType("Dir");
	
	@Override
	protected AbstractJavaCompilation getAbstractJavaCompilation()
			throws CompilationException {
		InnerEnum answer = null;
		answer = new InnerEnum(DIR,new ClassDecoration(JavaVisibility.PUBLIC));
		addEnumValue(answer);
		addField(answer);
		addMethod(answer);
		return answer ;
	}
	
	private final void addField(InnerEnum inner ){
		Field field = new Field( "dir" ,JDKFullyQualifiedJavaType.getStringInstance() );
		field.setUseDefaultValue(false);
		Decoration d =  field.getDecoration() ;
		d.setFinal(true);
		inner.addField(field);
	}
	
	private final void addMethod(InnerEnum inner ){
		Method method = new Method("Dir", new MethodDecoration(JavaVisibility.PRIVATE,false,false,true,false));
		method.addParameter(new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"dir" ) ) ;
		method.addBodyLine("this.dir = dir");
		inner.addMethod(method);
		method = new Method("toString");
		method.addBodyLine("return dir;");
		method.setReturnType(JDKFullyQualifiedJavaType.getStringInstance());
		method.addAnnotation("Override");
		inner.addMethod(method);
	}
	
	private final void addEnumValue(InnerEnum inner ){
		EnumField enumField = null; 
		Parameter parameter = null;
		
		enumField = new EnumField("DEFAULT" , "默认排序");
		parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"\"\"");
		enumField.addParameter(parameter,"\"\"");
		inner.addEnumFields(enumField);
		
		enumField = new EnumField("ASC" , "升序");
		parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"ASC");
		enumField.addParameter(parameter,"ASC");
		inner.addEnumFields(enumField);
		
		enumField = new EnumField("DESC" , "降序");
		parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"DESC");
		enumField.addParameter(parameter,"DESC");
		inner.addEnumFields(enumField);
	}
	
	@Override
	protected FullyQualifiedJavaType getType() {
		return null;
	}
}
